from pathlib import Path

from pydantic.v1 import BaseSettings


def get_root_path() -> Path:
    """
    获取项目根目录
    :return:
    """
    current_file_path = Path(__file__).parent.resolve()
    return current_file_path.parent


class Settings(BaseSettings):
    app_name: str = "Kevin API"

    app_version: str = "1.0.0"


class DevelopmentSettings(Settings):
    """
    开发环境
    """
    app_name = "Kevin FastAPI for Development"


class PRODSettings(Settings):
    """
    生产环境
    """
    app_name: str = "Kevin FastAPI for PROD"


_settings = None


class SettingConfig(object):
    """
        配置项
    """
    __settings: Settings = None

    @classmethod
    def get_settings(cls, profile: str = "development") -> Settings:
        """
        根据不同的profile获取 settings 配置，单例模式
        :param profile: development or production
        :return:
        """
        if cls.__settings is None:
            match profile:
                case "development":
                    cls._settings = DevelopmentSettings()
                case "production":
                    cls._settings = PRODSettings()
                case _:
                    cls._settings = DevelopmentSettings()
        return cls._settings
